package com.example.myapplication.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.example.myapplication.R;
import com.example.myapplication.bean.MessageListBean;
import com.example.myapplication.fragments.Fragment4;
import com.example.myapplication.utli.UtilsEnum;
import com.google.gson.Gson;

import org.json.JSONObject;

import java.util.List;

public class MessageListAdapter extends BaseAdapter {
    List<MessageListBean.DataDTO> data;
    Context context;

    public MessageListAdapter(List<MessageListBean.DataDTO> bean, Context mcontext) {
        this.data = bean;
        this.context = mcontext;
    }

    public MessageListAdapter() {
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position).getId();
    }

    @Override
    public long getItemId(int position) {
        return data.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view;

        if (data.get(position).getUser().getId() == UtilsEnum.ID) {
            view = inflater.inflate(R.layout.messageitemrigth, null);
        } else {
            view = inflater.inflate(R.layout.messageitem, null);
        }
        TextView tvTime = view.findViewById(R.id.tv_time_message);
        TextView tvName = view.findViewById(R.id.tv_name_message);
        TextView tvMessage = view.findViewById(R.id.tv_img_message);

        Log.e("TAG", "getView: " + data.get(position).toString());
        //TODO 更具当前用户改变 显示样式
        tvTime.setText(data.get(position).getDate() + "");
        tvName.setText(data.get(position).getContent());
        tvMessage.setText(data.get(position).getContent());
        return view;
    }
}
